package com.example.baseapp.controller;

import com.example.baseapp.common.ApiResponse;
import com.example.baseapp.entity.Breakfast;
import com.example.baseapp.service.BreakfastService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/breakfast")
public class BreakfastController {
    @Autowired
    private BreakfastService breakfastService;

    @PostMapping
    public ApiResponse<Breakfast> addBreakfast(@RequestBody Breakfast breakfast) {
        return ApiResponse.success(breakfastService.save(breakfast));
    }

    @GetMapping("/list")
    public ApiResponse<List<Breakfast>> list() {
        return ApiResponse.success(breakfastService.findAll());
    }

    @GetMapping("/detail/{id}")
    public ApiResponse<Breakfast> detail(@PathVariable Long id) {
        return ApiResponse.success(breakfastService.findById(id));
    }

    @DeleteMapping("/{id}")
    public ApiResponse<Void> deleteBreakfast(@PathVariable Long id) {
        breakfastService.deleteById(id);
        return ApiResponse.success(null);
    }

    @PutMapping
    public ApiResponse<Breakfast> updateBreakfast(@RequestBody Breakfast breakfast) {
        return ApiResponse.success(breakfastService.update(breakfast));
    }
} 